package com.xcb.my.bussiness;

import java.util.Map;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;

import com.plat.pool.LogicFacadeBase;
import com.ums.umsmsg.UmsMsg;
import com.ums.umsmsg.proc.Trans;
import com.xcb.my.dao.UserMapper;

public class UserLoginBusiness extends LogicFacadeBase{
	private static Logger log = Logger.getLogger(UserLoginBusiness.class);	
	
	
	@Autowired
	UserMapper userMapper;
	
	
	

	@Override
	public boolean packInMsg() {
		log.info("组 请求端 返回报文..."+getCFG(Trans.IN));
		try {
			inRspMsg =UmsMsg.pack(getCFG(Trans.IN), inMap);
			return ((inRspMsg.length > 0)? true : false);
		} catch (Exception e) {
			log.error("组 请求端 返回报文异常["+e+"]");
			return false;
		}
	}
	@Override
	public boolean transAuth() {
		return true;
	}

	@Override
	protected void setXYM() {
		ZD_XYM = "respCode";
		ZD_XYXX = "respMsg";
	}

	
	
	public boolean verInSig() {
		return true;
	}
	public boolean unpackInMsg() {
		log.info("拆 请求端 请求报文...");
		try {
			Map<String, String> tmpMap = UmsMsg.unpack(getCFG(Trans.IN), inReqMsg);
			inMap.putAll(tmpMap);
			return ((tmpMap.size() > 0)? true : false);
		} catch (Exception e) {
			log.error("拆 请求端 请求报文异常["+e+"]");
			return false;
		}
	}
	
	
	
	
	public boolean getContrastResult(){
		log.info("账号和密码匹配");
		int getContrastResult=0;
		try {
			getContrastResult = userMapper.getContrastResult(inMap);
		} catch (Exception e) {
			log.error("账号和密码匹配异常"+e);
			return false;
		}
		if(getContrastResult>0){
			log.info("账号和密码匹配成功");
			inMap.put("respCode", "000000");
			inMap.put("respMsg", "交易成功");
		}else{
			log.info("账号和密码匹配失败,原因可能是:1.账户名输入有误;2.忘记密码;");
			inMap.put("respCode", "000002");
			inMap.put("respMsg", "你输入的账户名或密码不正确,原因可能是:1.账户名输入有误;2.忘记密码;");
		}
		return true;
	}
	
	@SuppressWarnings("unchecked")
	public boolean getMerchInfo(){
		Map merInfoMap=null;
		try {
			merInfoMap = userMapper.getMerchInfo(inMap);
		} catch (Exception e) {
			log.error("查询用户信息异常"+e);
			return false;
		}
		if(merInfoMap!=null || !"".equals(merInfoMap)){
			inMap.putAll(merInfoMap);
		}else{
			log.info("未查询到该用户信息");
			return false;
		}
		return true;
	}
	
}
